package com.cpm.offcn.pubsub;

import com.cpm.offcn.utils.RabbitUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer01 {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtils.getConnection();
       final Channel channel = connection.createChannel();
       //创建队列
        channel.queueDeclare("QUEUE_01",false,false,false,null);
        ///

        //绑定交换机
        //队列名，交换机名，路由key
        channel.queueBind("QUEUE_01","EXCHANGE_WEATHER","");
        channel.basicQos(1);
        channel.basicConsume("QUEUE_01",false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("QUEUE_01队列收到的信息为：" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
